/**
 * @Date 2023-02-21 10:03:49
 * @Remark
 */

// react
import React from "react";
// lib
import { Space, Button, Popconfirm, Switch } from "antd";
// store
import { state } from "./state";
// controller
import { showRoleModal } from "./RoleModal/controller";
import { changeAdminState, delAdmin } from "./controller";

const TableColumns = [
  {
    title: "ID",
    dataIndex: "userId",
  },
  {
    title: "账号名称",
    dataIndex: "userName",
  },
  {
    title: "用户姓名",
    dataIndex: "fullName",
  },
  {
    title: "手机号",
    dataIndex: "phone",
  },
  {
    title: "启用状态",
    dataIndex: "state",
    render: (val: boolean, el: any) => {
      return (
        <Switch
          checked={val}
          onChange={(checked) => changeAdminState(checked ? 1 : 0, el.id)}
        />
      );
    },
  },
  {
    title: "操作",
    key: "action",
    fixed: "right" as any,
    render: (el: AdminItemDto) => {
      const edit = () => {
        state.editModal = el;
      };
      const role = () => {
        showRoleModal(el);
      };
      const del = () => {
        delAdmin(el.userId);
      };
      const reset = () => {
        state.pwdModal = el;
      };
      return (
        <Space>
          <Button size="small" type="primary" ghost onClick={role}>
            配置角色
          </Button>
          <Button size="small" type="primary" ghost onClick={edit}>
            编辑
          </Button>
          <Button size="small" type="primary" ghost onClick={reset}>
            修改密码
          </Button>
          <Popconfirm
            title={`确定删除【${el.fullName}】 的【${el.userName}】账号吗?`}
            onConfirm={del}
          >
            <Button size="small" danger ghost>
              删除
            </Button>
          </Popconfirm>
        </Space>
      );
    },
  },
];

export default TableColumns;
